package com.iflytek.cosmo.ocr.web.controller;

import com.iflytek.cosmo.ocr.common.exception.ParseDownLoadUrlExceptionAbstract;
import com.iflytek.cosmo.ocr.common.exception.VersionSetupOutputExceptionAbstract;
import com.iflytek.cosmo.ocr.model.domain.VersionSetupOutput;
import com.iflytek.cosmo.ocr.service.VersionSetupService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 版本配置详情控制器
 *
 * @author xqxia3
 * @date 2018年5月22日
 */
@RestController
@RequestMapping("/service/v1")
public class VersionSetupController {

    @Autowired
    private VersionSetupService versionSetupService;

    /**
     * 获取客户端版本升级配置信息
     *
     * @param projectName
     * @param profile
     * @return
     * @author xqxia3
     * @date 2018年4月22日
     */

    @GetMapping("/ver/{projectName}/{projectProfile:.+}")
    public VersionSetupOutput upgradeVersionInfo(@PathVariable("projectName") String projectName,
                                                 @PathVariable("projectProfile") String projectProfile)
            throws VersionSetupOutputExceptionAbstract, ParseDownLoadUrlExceptionAbstract {
        VersionSetupOutput result = versionSetupService.queryUpgradeVersionSetup(projectName, projectProfile);
        return result;
    }

    /**
     * 获取客户端运行时配置信息
     *
     * @param projectName
     * @param projectProfile
     * @return
     * @throws ParseDownLoadUrlExceptionAbstract
     */
    @GetMapping("/cfg/{projectName}/{projectProfile:.+}")
    public VersionSetupOutput runningVersionInfo(@PathVariable("projectName") String projectName,
                                                 @PathVariable("projectProfile") String projectProfile) throws VersionSetupOutputExceptionAbstract {
        VersionSetupOutput result = versionSetupService.queryRunningVersionSetup(projectName, projectProfile);
        return result;
    }

}
